﻿using System.DirectoryServices.AccountManagement;

namespace Inovout.Security
{
    public class WindowsUserService : IUserService
    {
        public IUser GetByUserName(string userName)
        {
            return new WindowsUser(userName);
        }

        public bool ValidateUser(string userName, string password)
        {
            ArgumentAssert.IsNotDefault(userName, "userName");
            ArgumentAssert.IsNotDefault(password, "password");
            using (PrincipalContext principalContext = new PrincipalContext(ContextType.Machine))
            {
                return principalContext.ValidateCredentials(userName, password);
            }
        }
    }
}
